<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%--<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>--%>
<%@ taglib prefix="depotnextdoor" tagdir="/WEB-INF/tags" %>
<%--当前页面是用户点击用户管理时，显示的页面--%>
<%--导入manage工程下的webapp目录下的WEB-INF目录下的tags目录的page.tag标签--%>
<depotnextdoor:page title="page.user.list" >
    <jsp:attribute name="css">
        <style type="text/css">
            #name-of-ban-user, #name-of-reset-user {
                font-weight: bold;
                color: red;
            }
        </style>
    </jsp:attribute>
    <jsp:attribute name="script">
        <script type="application/javascript">
            <%--<sec:authorize access="hasRole('OPT_USER_DELETE')">--%>
                $(".user-ban-btn").click(function () {
                    $("#id-of-user").val($(this).data("id"));
                    $("#name-of-ban-user").html($(this).data("name"));
                    $("#user-disable-confirm-modal").modal();
                });
                $(".btn-cancel-ban").click(function () {
                    $("#user-disable-confirm-modal").modal("hide");
                });
                $(".btn-confirm-ban").click(function () {
                    var username = $("#id-of-user").val();
                    $.post("users/delete.do", {
                        "username": username
                    }, function (result) {
                        if (result) {
                            window.location.href="${pageContext.request.contextPath}/users";
                        }
                    });
                    $("#user-disable-confirm-modal").modal("hide");
                });
            <%--</sec:authorize>--%>
        </script>
    </jsp:attribute>
    <jsp:body>
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="welcome">
                        首页
                    </a>
                </li>
                <li class="active">
                    用户管理
                </li>
            </ul><!-- /.breadcrumb -->
        </div>

        <div class="page-content">
            <input type="hidden" id="id-of-user">
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <div class="col-xs-12">
                            <h3 class="header smaller lighter blue">
                                <c:choose>
                                    <c:when test="${param.enabled == 'false'}">
                                        禁用
                                    </c:when>
                                    <c:otherwise>
                                        正常
                                    </c:otherwise>
                                </c:choose>
                                <span class="hidden-sm hidden-xs btn-group pull-right">
                                <a href="users?status=${param.status eq 'DISABLE' ? 'ENABLE' : 'DISABLE'}"
                                   class="${param.status eq 'DISABLE' ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger'}">
                                    <%--btn btn-sm btn-danger--%>
                                    <c:choose>
                                        <c:when test="${param.status eq 'DISABLE'}">
                                            <i class="ace-icon fa fa-eye"></i>
                                            正常用户
                                        </c:when>
                                        <c:otherwise>
                                            <i class="ace-icon fa fa-ban"></i>
                                            已禁用用户
                                        </c:otherwise>
                                    </c:choose>
                                </a>
                            </span>
                            </h3>
                            <%--用作查询的表单框--%>
                            <form action="users.do" method="get">
                                <div class="col-md-3 inline">
                                    <label>用户名</label>
                                    <input name="username" value='<c:out value="${adminVo.username}" />' type="text" placeholder="用户名"  autocomplete="off">
                                </div>
                                <div class="col-md-2 inline">
                                    <label>状态</label>
                                    <depotnextdoor:statusSelect fieldName="status" selectedStatus="" withNone="true" enableLabel="启用" disableLabel="禁用"/>
                                </div>

                                <div class="inline">
                                    <button type="submit" class="btn btn-info btn-sm">
                                        <i class="ace-icon fa fa-search bigger-110"></i>搜索
                                    </button>
                                </div>
                            </form>
                            <div class="hr hr-18 dotted"></div>
                            <table id="simple-table" class="table  table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>用户统一ID</th>
                                    <th>描述</th>
                                    <th class="hidden-md hidden-sm hidden-xs">状态</th>
                                    <th class="hidden-md hidden-sm hidden-xs">操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                <c:forEach items="${userPage.content}" var="user">
                                    <tr id="tr-${user.id}">
                                        <td><c:out value="${user.userUnionId}"/></td>
                                        <td><c:out value="${user.description}"/></td>
                                        <td class="hidden-md hidden-sm hidden-xs">
                                            <depotnextdoor:tags selectedStatus="${user.status.value}"/>
                                        </td>
                                        <td>
                                            <div class="hidden-sm hidden-xs btn-group">
                                                   <%--<sec:authorize access="hasAuthority('OPT_USER_DELETE')">--%>
                                                       <a
                                                          data-id="${user.id}"
                                                          data-name="${user.description}"
                                                          class="btn btn-minier btn-danger user-ban-btn">
                                                           <i class="ace-icon fa fa-trash-o bigger-120"></i>
                                                       </a>
                                                   <%--</sec:authorize>--%>
                                                <%--修改操作--%>
                                                <%--<sec:authorize access="hasAuthority('OPT_USER_EDIT')">--%>
                                                    <a href="users/edit.do?id=${user.id}"
                                                       class="btn btn-minier btn-info">
                                                        <i class="ace-icon fa fa-pencil bigger-120"></i>
                                                    </a>
                                                <%--</sec:authorize>--%>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <depotnextdoor:springPagePagination url="users.do" springPage="${userPage}" />
                        </div><!-- /.span -->
                    </div><!-- /.row -->
                    <div id="user-disable-confirm-modal" role="dialog" class="modal" tabindex="-1">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-body">
                                    <button type="button" class="bootbox-close-button close"
                                            data-dismiss="modal" aria-hidden="true">×
                                    </button>
                                    <div class="bootbox-body">禁用该账号，该账号所属公司帐号将全部被禁用！您确定要禁用用户<span
                                            id="name-of-ban-user"></span> ?
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-cancel-ban btn-default">
                                        取消
                                    </button>
                                    <button type="button" class="btn btn-confirm-ban btn-primary">
                                        确认
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div>
    </jsp:body>
</depotnextdoor:page>
